package proto;

import javafx.async.JavaTaskBase;
import javafx.async.RunnableFuture;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.animation.transition.TranslateTransition;

class FunctionTask extends JavaTaskBase{
    public-init var onInvoke:function();
    var runner:FunctionTaskRunnable;

    override protected function create () : RunnableFuture {
        runner = new FunctionTaskRunnable();
        if(onInvoke != null){
            runner.setFunction(onInvoke);
        }
        return runner;
    }
}

def executor = FunctionTask{
    onInvoke:function() {
        for(i in [1..1000]){
            println ("Do someting {i}");
        }
    }
}

def circle = Circle {
	centerX: 100, centerY: 100
	radius: 40
	fill: Color.BLACK
}

def anim = TranslateTransition {node: circle, byX: 50, byY:50 repeatCount:TranslateTransition.INDEFINITE, autoReverse:true};
anim.play();

def btn = Button {
        
	text: "Execute"
	action: function() {

            executor.start();
	}
}

Stage {
	title : "MyApp"
	scene: Scene {
		width: 200
		height: 200
		content: [ btn, circle ]
	}
}
